package com.jjx.dao;

import com.jjx.domain.SysUser;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface IUserMapper extends Mapper<SysUser> {

    @Select("select  * from sys_user where login_name = #{username}")
    SysUser findByUsername(String username);

    @Select("<script>" +
            "select * from sys_user" +
            "<where>" +
            "<if test='login_name!=null and login_name != \"\"'> and login_name like #{login_name}</if>" +
            "<if test='sex!=null and sex != \"\"'> and sex=#{sex}</if>" +
            "</where>" +
            "</script>")
    @Results({
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "login_name",column = "login_name"),
            @Result(property = "pwd",column = "pwd"),
            @Result(property = "img",column = "img"),
            @Result(property = "email",column = "email"),
            @Result(property = "sex",column = "sex"),
            @Result(property = "mobile",column = "mobile"),
            @Result(property = "status",column = "status"),
            @Result(property = "name",column = "name"),
            @Result(property = "role_id",column = "role_id"),
            @Result(property = "org_id",column = "org_id"),
            @Result(property = "role",column = "role_id",javaType = com.jjx.domain.Role.class,
                    one = @One(select = "com.jjx.dao.IRoleMapper.findRole",fetchType = FetchType.LAZY)),
            @Result(property = "department",column = "org_id",javaType = com.jjx.domain.Department.class,
                    one = @One(select = "com.jjx.dao.IDepartmentMapper.findDepartment",fetchType = FetchType.LAZY)),
    })
    List<SysUser> findAllOrByCondition(SysUser sysUser);
}
